_ = require 'underscore'
ImportFiles = require './import_files'
BaseConfig = require '../../helpers/base_config'
WebConfig = require './web_config'


viewContentHandler =
  ###*
   * [home description]
   * @param  {[type]} req      [description]
   * @param  {[type]} view     [description]
   * @param  {[type]} title    [description]
   * @param  {[type]} navIndex [description]
   * @param  {[type]} data     [description]
   * @return {[type]}          [description]
  ###
  home : (req, view, title, navIndex, data) ->
    welcomeDialog = BaseConfig.getDialogConfig
      selfId : 'welcomeDialog'
      title : '个人感言'
      data : data.welcomeDialogContent

    articlesContent = data.articlesContent;
    _.each articlesContent, (articleContent) ->
      articleContent.date = formatDate articleContent.createTime
    # console.log data.articlesContent

    articleListDialog = BaseConfig.getDialogConfig
      selfId : 'articleList'
      title : '文章分享'
      data : articlesContent

    renderData = 
      title : title || ''
      importObj : ImportFiles.getImportObj view
      header : WebConfig.getHeader navIndex || 0
      viewContent :
        welcomeDialog : welcomeDialog
        articleListDialog : articleListDialog
      
    return renderData

###*
 * [formatDate description]
 * @param  {[type]} createTime [description]
 * @return {[type]}            [description]
###
formatDate = (createTime) ->
  month = createTime.getMonth() + 1
  day = createTime.getDate()
  if month < 10
    month = '0' + month
  if day < 10
    day = '0' + day
  return {
    month : month
    day : day
  }

module.exports = viewContentHandler